<!DOCTYPE html>
<html class="ui-page-login">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link href="./css/mui.min.css" rel="stylesheet" />
		<link href="./css/setting.css" rel="stylesheet">
		<link href="./css/form2.css" rel="stylesheet">
		<style type="text/css" abt="234"></style>
		<style>
			
		</style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">注册</h1>
		</header>
		<div class="mui-content">
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label style="font-size: 16px;">手机号</label>
					<input id='mobile' type="email" class="mui-input-clear mui-input" placeholder="请输入注册手机号">
				</div>
					<div style="position: relative;">
						<div class="mui-input-row">
							<input id='code' type="email" placeholder="请输入验证码" style="width: 60%;">
							<button type="button"  id="btn_send_yanzheng" style="border: 0;" style="" onclick="getCode('getCode');">获取验证码</button>
						</div>
					</div>
				<div class="mui-input-row">
					<label style="font-size: 16px;">密码</label>
					<input id='password' type="password" class="mui-input-clear mui-input" placeholder="请输入密码">
				</div>
			</form>
			<div class="mui-button-row">
				<button id='reg' class="mui-btn mui-btn-warning bgcolor mui-pull-center" style="width: 100%;" onclick="regist();">注册</button>
			</div>
			<div class="mui-content-padded">
			</div>
			<div id="supplementModal" class="mui-popover" title="补充个人信息">
			<div class="modal-content">
				<form class="mui-input-group" id="supplementForm">
					<div class="mui-input-row">
							<select id="provinceSelect" onchange="showCitySelect(this.value);">
								<option value="">请选择省份</option>
							</select>
						</div>
					<div class="mui-input-row">
							<select id="citySelect" onchange="showSubCitySelect(this.value);">
								<option value="">请选择城市</option>
							</select>
						</div>
					<div class="mui-input-row">
							<select id="subCitySelect">
								<option value="">请选择区县</option>
							</select>
					</div>
					<div class="mui-input-row">
						<input type="text" class="" name="realName" placeholder="请填写您的真实名称" id="realName" maxlength="20">
					</div>
					<div class="mui-input-row">
						<input type="text" class="" name="appInvitationCode" placeholder="请填写邀请码" id="appInvitationCode" maxlength="20">
					</div>
				<button type="button" class="mui-btn mui-btn-warning mui-btn-outlined" onclick="supplementAppUser();">保存</button>
				</form>	
			</div>
		</div>
		</div>
		<script src="./js/mui.js"></script>
		<script src="./js/jquery-1.10.2.min.js"></script>
		<script src="./js/vue.min.js"></script>
		<script src="./js/common.js"></script>
		<script>
			mui.init({
				swipeBack: true //启用右滑关闭功能
			});
var appUserId = '';
function regist() {
	var phone = $("#mobile").val();
	var password = $("#password").val();
	var code = $("#code").val();
	if(isNull(phone)) {
		mui.toast('请输入手机号');
		return;
	}
	if(!(/^1[34578]\d{9}$/.test(phone))) {
		mui.toast('手机号填写有误');
		return;
	}
	if(isNull(code)) {
		mui.toast('请输入短信验证码');
		return;
	}
	if(isNull(password)) {
		mui.toast('请输入密码');
		return;
	}
	var checkCodeResult = ajaxAction(root + "index/checkSMSCode", {
		mobile: phone,
		code: code
	});
	if(checkCodeResult.status == "failed") {
		mui.toast(checkCodeResult.msg);
		return;
	}
	var url = root + "myCenter/regist";
	mui.post(url, {
			mobile: phone,
			password: password
		},
		function(data) {
			var status = data.status;
			if(status == "success") {
				appUserId = data.data.id;
				mui('#supplementModal').popover('show');
			}
			if(status == "failed") {
				mui.alert(data.msg);
			}
		}, 'json'
	);
}

/*按钮倒计时60秒*/
var wait = 120;

function getCode(sender) {
	if(sender == "getCode") {
		var mobile = $("#mobile").val();
		if(isNull(mobile) || (!(/^1[34578]\d{9}$/.test(mobile)))) {
			mui.toast("请输入正确手机号");
			return;
		}
		var result = ajaxAction(root + "index/getSMSCode", {
			mobile: mobile
		});
		if(result.status == "failed") {
			mui.toast(result.msg);
			return;
		}
	}
	if(wait == 0) {
		$("#btn_send_yanzheng").attr("disabled", false);
		$("#btn_send_yanzheng").html("获取验证码");
		wait = 120;
	} else {
		$("#btn_send_yanzheng").attr("disabled", true);
		$("#btn_send_yanzheng").html("重新发送(" + wait + "s)");
		wait--;
		setTimeout(function() {
			getCode("");
		}, 1000)
	}
}

$(function() {
	checkVersion();
	showProvinceList();
});

function supplementAppUser() {
	var province = $("#provinceSelect").val();
	var city = $("#citySelect").val();
	var subCity = $("#subCitySelect").val();
	var realName = $("#realName").val();
	var appInvitationCode = $("#appInvitationCode").val()
	if(isNull(province) || isNull(city) || isNull(subCity) || isNull(realName)) {
		mui.toast("补充信息必须填写完整");
		return false;
	}
	var url = root + "/myCenter/updateAppUserInfoAreaInfo";
	mui.post(url, {
		id: appUserId,
		areaProvinceId: province,
		areaCityId: city,
		areaId: isNull(subCity) ? 0 : subCity,
		realName: realName,
		appInvitationCode: appInvitationCode
	}, function(result) {
		var code = result.status;
		if(code == 'success') {
			mui('#supplementModal').popover('hide');
			alert("资料补充成功，请登录和大家一起加入关爱筹吧！");
			mui.openWindow('login.html', '', {});
		} else {
			mui.toast(result.msg);
		}
	}, 'json');
}

		</script>
	</body>

</html>